home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / docs / linux-do / programm / lpg-0.4 / lpg-0 / LPG / examples / translate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-10  |  2.3 KB  |  76 lines

  1. /*
  2.  *  AUTHOR: Sven Goldt (goldt@math.tu-berlin.de)
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of the GNU General Public License
  6.  *  as published by the Free Software Foundation; either version 2
  7.  *  of the License, or (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14. */
  15.  
  16.  
  17. #include <string.h>
  18.  
  19. static struct s_notes
  20. {
  21.  float frequency;
  22.  char name[4];
  23. } notes[] = {
  24. 16.4 , "c-0", 17.3 , "c#0", 18.4 , "d-0", 19.4 , "d#0",
  25. 20.6 , "e-0", 21.8 , "f-0", 23.1 , "f#0", 24.5 , "g-0",
  26. 26.0 , "g#0", 27.5 , "a-0", 29.1 , "a#0", 30.9 , "h-0",
  27.  
  28. 32.7 , "c-1", 34.6 , "c#1", 36.7 , "d-1", 38.9 , "d#1",
  29. 41.2 , "e-1", 43.7 , "f-1", 46.2 , "f#1", 49.0 , "g-1",
  30. 51.9 , "g#1", 55.0 , "a-1", 58.3 , "a#1", 61.7 , "h-1",
  31.  
  32. 65.4 , "c-2", 69.3 , "c#2", 73.4 , "d-2", 77.8 , "d#2",
  33. 82.4 , "e-2", 87.3 , "f-2", 92.5 , "f#2", 98.0 , "g-2",
  34. 103.8, "g#2", 110.0, "a-2", 116.5, "a#2", 123.5, "h-2",
  35.  
  36. 130.8, "c-3", 138.6, "c#3", 146.8, "d-3", 155.6, "d#3",
  37. 164.8, "e-3", 174.6, "f-3", 185.0, "f#3", 196.0, "g-3",
  38. 207.7, "g#3", 220.0, "a-3", 233.1, "a#3", 246.9, "h-3",
  39.  
  40. 261.6, "c-4", 277.2, "c#4", 293.7, "d-4", 311.1, "d#4",
  41. 329.6, "e-4", 349.2, "f-4", 370.0, "f#4", 392.0, "g-4",
  42. 415.3, "g#4", 440.0, "a-4", 466.2, "a#4", 493.9, "h-4",
  43.  
  44. 523.3, "c-5", 554.4, "c#5", 587.3, "d-5", 622.3, "d#5",
  45. 659.3, "e-5", 698.5, "f-5", 740.0, "f#5", 784.0, "g-5",
  46. 830.6, "g#5", 880.0, "a-5", 932.3, "a#5", 987.8, "h-5",
  47.  
  48. 1046.5, "c-6", 1108.7, "c#6", 1174.7, "d-6", 1244.5, "d#6",
  49. 1318.5, "e-6", 1396.6, "f-6", 1480.0, "f#6", 1568.0, "g-6",
  50. 1661.2, "g#6", 1760.0, "a-6", 1864.7, "a#6", 1975.5, "h-6",
  51.  
  52. 2093.0, "c-7", 2217.5, "c#7", 2349.3, "d-7", 2489.0, "d#7",
  53. 2637.0, "e-7", 2793.8, "f-7", 2960.0, "f#7", 3136.0, "g-7",
  54. 3322.4, "g#7", 3520.0, "a-7", 3729.3, "a#7", 0.0 , "0",
  55. };
  56.  
  57. float name_to_val(char *tune)
  58. {
  59. struct s_notes *ptr;
  60.  
  61.  for (ptr=notes; ptr->frequency !=0; ptr++)
  62.   if (strncmp(tune,ptr->name,3) == 0) return(ptr->frequency);
  63.  
  64. return(0.0);
  65. }
  66.  
  67. char *val_to_name(float frequency)
  68. {
  69. struct s_notes *ptr;
  70.  
  71.  for (ptr=notes; ptr->frequency !=0; ptr++)
  72.   if (ptr->frequency == frequency) return(ptr->name);
  73.  
  74. return(NULL);
  75. }
  76.